package arcane.network;

import ggn.client.Client;

import java.io.IOException;
import java.util.List;
import java.util.Vector;

public class Room {
	String name;
	private List<Client> room;
	Client host;
	int maxClients;

	public Room(Client host, int maxClients) {
		this.host = host;
		room = new Vector<Client>();
		if (host != null)
			room.add(host);
		this.maxClients = maxClients;
		name = "Room";
	}

	/**
	 * Returns the name of this room.
	 * 
	 * @return name of this room.
	 */
	public String getName() {
		return name;
	}

	/**
	 * Sets the name of this room.
	 * 
	 * @param name
	 *            new name for this room.
	 */
	public void setName(String name) {
		this.name = name;
	}

	public Client getHost() {
		return host;
	}

	public int getMaxClients() {
		return maxClients;
	}

	/**
	 * Returns current number of clients in this room.
	 * 
	 * @return clients in this room.
	 */
	public int getNumberClients() {
		return room.size();
	}

	/**
	 * Returns the clients in this room.
	 * 
	 * @return clients in room.
	 */
	public List<Client> getClients() {
		return room;
	}

	/**
	 * Returns true if specified client was successfully added to this room. A
	 * room cannot have more clients than its maximum specified number.
	 * 
	 * @param client
	 *            specified client to add to room.
	 * @return whether client was added
	 */
	public boolean addClient(Client client) {
		if (room.size() < maxClients) {
			return room.add(client);
		} else
			return false;
	}
	
	public boolean removeClient(Client c){
		return room.remove(c);
	}

	public void messageClients(Object message) throws IOException {
		for (int i = 0; i < room.size(); i++) {
			room.get(i).writeObject(message);
		}
	}
}